// 1. 退出登录
function logOut() {
    $("#safeout").click(function() {
        delCookie("uid"); // 清除cookie
        delCookie("realName");
        delCookie("userType");
        window.location.href = "index.html"; // 重定向到登录页面
    });
}

// 2.校验参数是否为空,并隐藏和显示对应的提示
function checkIsEmpty(checkPara, showId, hideId, minLength, maxLength) {
    if (checkPara == "" || (checkPara != "" && (checkPara.length < minLength || checkPara.length > maxLength))) {
        $(showId).show();
        $(hideId).hide();
        return true;
    }
    return false;
}

// 3.查询所有的沙发简单信息
function getAllSimpleSofaInfo() {
    $.ajax({
        url : "/SofaGuest/sofa/qrySimpleSofa.do",
        type : "post",
        data : {
            "address" : "null",
            "sex" : "1",
            "minAge" : 0,
            "maxAge" : 99,
            "pernum" : 1
        },
        dataType : "json",
        success : function(result) {
            if ("0000" == result.status) {
                // alert(result.detial);
                var sofaInfos = result.data;
                dealSofaInfo(sofaInfos);
            }
            else {
                alert(result.detial);
                window.location.href = "homePage.html";
            }
        }
    });
}

// 4.拼装简单沙发信息的公共方法
function dealSofaInfo(sofaInfos) {
    for ( var i = 0; i < sofaInfos.length; i++) {
        var sofaInfo = sofaInfos[i];
        var sofaId = sofaInfo.sofa_id;
        var sofaType = sofaInfo.sofa_type;
        var join_date = sofaInfo.join_date;
        var emg = sofaInfo.sofa_emg;
        var li = '<li class="bbda">' + '<div class="minipic"><img src=/SofaGuest' + emg
                + ' width="64px" height="64px"></div><!-- 图 -->' + '<h4>沙发类型:' + sofaType + '</h4>' + '<h4> 日   期  :'
                + join_date + '</h4>'
                + '<a href="Javascript:void(0)" id="chkdetail" onclick="sofaDetial(this)">查看详情</a></li>';
        var $li = $(li);
        $li.data("sofaId", sofaId);
        $("#sofaInfoLi").append($li);
    }
}

// 5.点击找沙发的页面的方法
function gotoqrySofaHtml() {
    addCookie("qryTag", 1, 1);
    window.location.href = "qrySofa.html";
}

// 6.ajax请求错误信息
function errorMsg() {
    alert("系统异常,请稍后重试");
}

// 7.转换订单的状态
function transOrderStatus(orderStatus) {
    if (1 == orderStatus) {
        return "预订";
    }
    else if (2 == orderStatus) {
        return "接受";
    }
    else if (3 == orderStatus) {
        return "离开";
    }
    else if (4 == orderStatus) {
        return "已评价";
    }
    else if (5 == orderStatus) {
        return "退单";
    }
}

// 8.转换沙发类型
function transSofaType(sofaType){
    if("睡眠沙发"==sofaType){
        return 1;
    }
    if("空闲床位"==sofaType){
        return 2;
    }
    if("一起睡地板"==sofaType){
        return 3;
    }
    if("1"==sofaType){
        return "睡眠沙发";
    }
    if("2"==sofaType){
        return "空闲床位";
    }
    if("3"==sofaType){
        return "一起睡地板";
    }
}

// 9.转换性别
function transSex(sex){
    if("不限"==sex){
        return 1;
    }
    if("男"==sex){
        return 2;
    }
    if("女"==sex){
        return 3;
    }
    if("1"==sex){
        return "不限";
    }
    if("2"==sex){
        return "男";
    }
    if("3"==sex){
        return "女";
    }
}

// 10.转换baseres物品
function getBasereId(basere){
    if("餐饮"==basere){
        return "#baseres1";
    }
    if("洗浴"==basere){
        return "#baseres2";
    }
    if("停车"==basere){
        return "#baseres3";
    }
    if("WIFI"==basere){
        return "#baseres4";
    }
    if("空调"==basere){
        return "#baseres5";
    }
    if("宠物"==basere){
        return "#baseres6";
    }
}

// 11 显示div
function showDiv(divId,showClass){
    if(showClass==null){
        $(".canShow").hide();
    }else{
        $("."+showClass+"").hide();
    }
    $("#"+divId+"").show();
}

// 12.转换性别
function transUserType(userType){
    if("管理员"==userType){
        return "0";
    }
    if("沙客"==userType){
        return "1";
    }
    if("沙主"==userType){
        return "2";
    }
    if("0"==userType){
        return "管理员";
    }
    if("1"==userType){
        return "沙客";
    }
    if("2"==userType){
        return "沙主";
    }
}